# import cv2
# import numpy as np

# # 读取图像
# image = cv2.imread('D:\\zxd\\lecture\\imageProcessing\\11img-02\\11img\\DIP3E_Original_Images_CH10\\Fig1060(a)(car on left).tif', cv2.IMREAD_COLOR)

# # 将图像转换为灰度图像
# gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# # 使用Laplacian算子进行锐化
# lap = cv2.Laplacian(gray_image, cv2.CV_64F)

# # 将Laplacian结果转换回8位整数
# lap = cv2.convertScaleAbs(lap)

# # 将锐化后的图像与原始图像相加，得到最终结果
# sharpened = cv2.addWeighted(gray_image, 1.0, lap, 0.5, 0)

# # 显示原始图像和锐化后的图像
# cv2.imshow('Original Image', gray_image)
# cv2.imshow('Sharpened Image', sharpened)

# # 等待按键后关闭窗口
# cv2.waitKey(0)
# cv2.destroyAllWindows()


# img_name = '000002.jpg'
# print(img_name[:-4])
import os
import re
dataPath = r'data\pose4\train'
image_path = os.path.join(dataPath, r'images')
label_path_old = os.path.join(dataPath, r'labels')
label_path_new = os.path.join(r'data\pose_detect', r'labels1')
iii = '1 0 0.5 0.5 1 1 0.177683 0.364205 0.181322 0.266583 0.150394 0.553191 0.302001 0.554443 0.23772 0.802253 0.385688 0.523154 0.418435 0.795995 0.681625 0.544431 0.722862 0.613267 0.656155 0.718398 0.70285 0.429287 0.816252 0.598248 0.828987 0.795995 0.754397 0.229036 0.452395 0.39174'
id = '000002'
pattern = r"(?<=\S\s)\S+(?:\s\S+){3}(?=\s)"

label_path_old_f = open(os.path.join(label_path_old, id+'.txt'),'r')
label_path_new_f = open(os.path.join(label_path_new, id+'.txt'),'w')
xywhn = [0.2,0.3,0.4,0.5]
xn = xywhn[0]
yn = xywhn[1]
wn = xywhn[2]
hn = xywhn[3]
replacement = f'{xn} {yn} {wn} {hn}'
for line in label_path_old_f.readlines():
    new_text = re.sub(pattern, replacement, line, count=1)
    print(line)
    print(new_text)
label_path_old_f.close()
label_path_new_f.close()